﻿using HyEduOnline.Entities;
using HyEduOnline.Server.Admin;
using HyEduOnline.Server.Teacher;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data.Common;
using System.Data;
using WebSite.Areas.WebApi.Controllers;

//using Excel = Microsoft.Office.Interop.Excel;//ASP.NET中Excel的命名空间

using Microsoft.Practices.EnterpriseLibrary.Data;
using HyEduOnline.Models;
using HyEduOnline.Server.Common;
using System.Text;
namespace WebSite.Areas.WebApi.Controllers
{
    public class TestLibExtController : TestLibController
    {

        private string uploadPath = "~/upload/TestLibFile/";//试题上传路径Test
        private string errorPath = "~/upload/error/";//错误文件上传路径
        private string CurrentFileName = "";//当前文件名
        private TestLibDAO TLbDao = new TestLibDAO();    //定义TestLibDAO的对象
        private TestLibOptionDAO TLOpDao = new TestLibOptionDAO();  //定义TestLibOptionDAO的对象






        /// <summary>
        /// 获取节
        /// </summary>
        /// <param name="ID">对应章的Id</param>
        /// <returns></returns>
        public JsonResult GetSession(int ID)
        {
            string whereClause = "I_ParentID=" + ID;
            TList<TbTeaCatalog> tempObject = new TeaCatalogDAO().GetByPage(whereClause, 0, int.MaxValue);

            return Json(tempObject, JsonRequestBehavior.AllowGet);
        }



        /// <summary>
        /// 筛选试题
        /// </summary>
        /// <param name="firstResult">起始位置</param>
        /// <param name="pagesize">页面大小</param>
        /// <param name="orderBy">排序列</param>
        /// <param name="condition">筛选条件</param>
        /// <returns></returns>
        public Object DefaultSearch(int firstResult, int pagesize, string orderBy = "ID", string condition = "1=1")
        {

            int totalCount = 0;  //总的数据记录条数
            condition = HttpUtility.UrlDecode(condition);



            IList<TbTestLib> userList = TestLibDAO.getByPageDataBase(firstResult, pagesize, orderBy, condition, out totalCount);
            return this.Json(new
            {
                DataCount = totalCount,
                Data = userList
            }, JsonRequestBehavior.AllowGet);
        }


        public Object Search(int firstResult, int pagesize, string orderBy, string condition)
        {

            int totalCount = 0;  //总的数据记录条数
            condition = HttpUtility.UrlDecode(condition);
            long StrategyID = frontCurrentTea.GetCurrentStrategyID();//获取当前策略的Id

            string whereClause = "I_StrategyID=" + StrategyID;

            TList<TbTestLibPaperDetail> tempPPDid = new TestLibPaperDetailDAO().GetByPage(whereClause, 0, int.MaxValue);
            string tempIdStr = "";
            if (tempPPDid.Count > 0)
            {
                int count = tempPPDid.Count;
                --count;
                int i;
                for (i = 0; i < tempPPDid.Count; i++)
                {
                    int TempLibId = int.Parse(tempPPDid[i].ILibId.ToString());
                    if (i != count)
                    {
                        tempIdStr = tempIdStr + "'" + TempLibId + "',";
                    }
                    else
                        tempIdStr = tempIdStr + "'" + TempLibId + "'";
                }
                condition = condition + "and ID not in(" + tempIdStr + ")";
            }
            IList<TbTestLib> userList = TestLibDAO.getByPageDataBase(firstResult, pagesize, orderBy, condition, out totalCount);
            return this.Json(new
            {
                DataCount = totalCount,
                Data = userList
            }, JsonRequestBehavior.AllowGet);
        }





        #region 试题的删除+DeleteTestLib
        public int DeleteTestLib(string ids)
        {

            try
            {
                string[] SIds = ids.Split(new char[] { ',' });

                foreach (var SId in SIds)
                {
                    int IId = int.Parse(SId);//对应表的Id
                    TbTestLib TestLib = new TestLibDAO().GetByID(IId);//获取到主表Id对应的那条数据
                    if (TestLib != null)
                    {
                        TLbDao.Del(TestLib);  //删除TestLib表中的对应该id的那条数据

                        string WhereClause = "I_LibID=" + IId;  //构建查询条件
                        TList<TbTestLibOption> TestLibOptionList = new TestLibOptionDAO().GetByPage(WhereClause, 0, int.MaxValue);  //在tb_TestLibOption中查找LibId==tb_TestLib表中当前id的数据

                        if (TestLibOptionList.Count > 0)  //找到该查询条件下的数据
                        {
                            foreach (var item in TestLibOptionList)  //存在多个的话，依次删除
                            {
                                TLOpDao.Del(item);
                            }
                        }
                    }

                }
                return 1;
            }
            catch (Exception ex)
            {
                return 0;
            }
            return 0;
        }
        #endregion




        //<summary>
        //根据试题类型来生成新的试题
        //修改12.23,建立试题模板的时候，CourseID默认为0的问题
        //</summary>
        //<param name="QuestType"></param>
        //<returns></returns>
        public JsonResult GenNewQuestion(int QuestType, int CourseID)
        {

            frontCurrentTea.SetCurrentQuestionKind(QuestType);//获取当前试题类型
            QuestExt myQuest = null;
            switch (QuestType)
            {
                case 1:
                    //单选

                    //生成模板 
                    myQuest = GenQuestItem(QuestType);
                    //更新为指定的类型
                    myQuest.LibItem.IProblemType = 1;
                    myQuest.LibItem.ICousreId = CourseID;  //设置试题所属的课程  添加于12.23
                    //写入数据库
                    AddNewQuestion(myQuest);
                    //将当前试题的Id给session
                    frontCurrentTea.SetCurrentQuestionID(myQuest.LibItem.Id);

                    break;
                case 2:
                    //多选
                    myQuest = GenQuestItem(QuestType);
                    //更新为指定的类型
                    myQuest.LibItem.IProblemType = 2;
                    myQuest.LibItem.ICousreId = CourseID;  //设置试题所属的课程  添加于12.23
                    //写入数据库
                    AddNewQuestion(myQuest);
                    //将当前试题的Id给session
                    frontCurrentTea.SetCurrentQuestionID(myQuest.LibItem.Id);

                    break;
                case 3://判断题
                    //生成模板 
                    myQuest = GenQuestItem(QuestType);
                    //更新为指定的类型
                    myQuest.LibItem.IProblemType = 3;
                    myQuest.LibItem.ICousreId = CourseID;  //设置试题所属的课程  添加于12.23
                    //写入数据库
                    AddNewQuestion(myQuest);
                    //将当前试题的Id给session
                    frontCurrentTea.SetCurrentQuestionID(myQuest.LibItem.Id);
                    break;
                default:
                    break;
            }

            return Json(myQuest, JsonRequestBehavior.AllowGet);
        }


        /// <summary>
        /// 新增问题项
        /// </summary>
        /// <param name="questItem"></param>
        public void AddNewQuestion(QuestExt questItem)
        {
            if (questItem.LibItem != null)
            {
                new TestLibDAO().Insert(questItem.LibItem);


                //更新option的id修改9.6/15.32
                if (questItem.OptionList != null)
                {
                    if (questItem.OptionList.Count > 0)
                    {
                        foreach (var item in questItem.OptionList)
                        {
                            item.ILibId = questItem.LibItem.Id;
                        }

                        new TestLibOptionDAO().Insert(questItem.OptionList);
                    }
                }
            }
        }

        /// <summary>
        /// 生成一个通用的试题模板
        /// </summary>
        /// <returns></returns>
        public QuestExt GenQuestItem(int QuestType)
        {

            QuestExt tmpQuesItem = new QuestExt();
            TbTestLib libItem = new TbTestLib();

            switch (QuestType)
            {

                case 1:
                case 2:

                    //生成选项

                    TList<TbTestLibOption> opList = new TList<TbTestLibOption>();
                    TbTestLibOption op1 = new TbTestLibOption();
                    op1.SOptionName = "选项一";
                    op1.IIsTrue = 1;

                    TbTestLibOption op2 = new TbTestLibOption();
                    op2.SOptionName = "选项二";
                    op2.IIsTrue = 0;


                    opList.Add(op1);
                    opList.Add(op2);
                    tmpQuesItem.OptionList = opList;
                    break;
                case 3://判断题10.3
                    //生成选项

                    TList<TbTestLibOption> opListt = new TList<TbTestLibOption>();
                    TbTestLibOption opt1 = new TbTestLibOption();
                    opt1.SOptionName = "正确";
                    opt1.IIsTrue = 0;

                    TbTestLibOption opt2 = new TbTestLibOption();
                    opt2.SOptionName = "错误";
                    opt2.IIsTrue = 0;


                    opListt.Add(opt1);
                    opListt.Add(opt2);
                    tmpQuesItem.OptionList = opListt;


                    break;
                default:
                    break;

            }
            //生成基本题;



            //生成选项




            tmpQuesItem.LibItem = libItem;

            return tmpQuesItem;
        }



        /// <summary>
        /// 删除被勾选的选项
        /// </summary>
        /// <param name="Ids">被勾选的选项ID串</param>
        public void DelOptions(int id)
        {
            TbTestLibOption tempOption = new TestLibOptionDAO().GetByID(id);
            if (tempOption != null)
            {
                TLOpDao.Del(tempOption);
            }

        }



        /// <summary>
        /// 新增选项
        /// </summary>
        /// <param name="LibId">当前试题的id</param>
        public JsonResult AddOptions()
        {
            long LibId = frontCurrentTea.GetCurrentQuestionID();//获取当前试题的Id
            TbTestLibOption tempOption = new TbTestLibOption();
            tempOption.ILibId = LibId;
            tempOption.SOptionName = "新增选项";
            tempOption.IIsTrue = 0;//默认选项为错误的
            TLOpDao.Insert(tempOption);
            string whereClause = "I_libID=" + LibId;
            TList<TbTestLibOption> tempOptionList = new TestLibOptionDAO().GetByPage(whereClause, 0, int.MaxValue);

            if (tempOptionList.Count > 0)
            {
                return Json(tempOptionList, JsonRequestBehavior.AllowGet);
            }

            return null;

        }


        /// <summary>
        ///  在删除部分选项后重新从数据库查找选项集
        /// </summary>
        /// <param name="TestLibId"></param>
        /// <returns></returns>
        public JsonResult FindOption()
        {
            string TestLibId = frontCurrentTea.GetCurrentQuestionID().ToString();
            long id = long.Parse(TestLibId);
            string whereClause = "I_libID=" + id;
            TList<TbTestLibOption> tempOptionList = new TestLibOptionDAO().GetByPage(whereClause, 0, int.MaxValue);

            if (tempOptionList.Count > 0)
            {
                return Json(tempOptionList, JsonRequestBehavior.AllowGet);
            }

            return null;
        }




        /// <summary>
        /// 更新，写入选项
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <param name="pk"></param>
        public void UpdateOptionName(string name, string value, int pk)
        {


            if (string.IsNullOrEmpty(value))
            {
                throw new Exception("出错了,不能是空白！");
                return;
            }
            else
            {
                if (pk > 0)
                {

                    TestLibOptionDAO tloDao = new TestLibOptionDAO();
                    TbTestLibOption tmpItem = tloDao.GetByID(pk);
                    if (tmpItem != null)
                    {
                        tmpItem.SOptionName = value;
                        tloDao.Update(tmpItem);
                    }

                }
            }


        }
        /// <summary>
        /// 更新选项
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <param name="pk"></param>
        public void UpdateOptionAnswer(string name, string value, int pk)
        {


            if (string.IsNullOrEmpty(value))
            {
                throw new Exception("出错了,不能是空白！");
                return;
            }
            else
            {
                if (pk > 0)
                {

                    TestLibOptionDAO tloDao = new TestLibOptionDAO();
                    TbTestLibOption tmpItem = tloDao.GetByID(pk);
                    if (tmpItem != null)
                    {
                        //TODO,如果是单选且为真，需要把所有的其它答案设为false
                        int Kind = frontCurrentTea.GetCurrentQuestionKind();
                        int Istrue = int.Parse(value);
                        if (Kind == 1 && Istrue == 1)  //如果本题是单选题并且当前选项为正确选项
                        {
                            long tempTestLibId = frontCurrentTea.GetCurrentQuestionID();//获取选项的Id
                            string whereClause = "I_libID=" + tempTestLibId;//获取当前题对应的选项集
                            TList<TbTestLibOption> tempOptionList = new TestLibOptionDAO().GetByPage(whereClause, 0, int.MaxValue);
                            if (tempOptionList.Count > 0)
                            {
                                foreach (var item in tempOptionList)
                                {
                                    if (item.Id != tmpItem.Id)
                                    {

                                        item.IIsTrue = 0;//置其余选项为错误选项
                                        tloDao.Update(item);
                                    }
                                }
                            }
                        }

                        tmpItem.IIsTrue = int.Parse(value);
                        tloDao.Update(tmpItem);

                    }

                }
            }


        }


        /// <summary>
        /// 更新当前试题
        /// </summary>
        /// <param name="Testlib">TestLib表的对象</param>
        public void QuestionUpdate(TbTestLib Testlib)
        {
            string tempID = frontCurrentTea.GetCurrentQuestionID().ToString();  //获取当前试题的id
            int Id = int.Parse(tempID);
            TbTestLib tempLib = TLbDao.GetByID(Id);  //获取该id下的对应试题


            tempLib.ICousreId = Testlib.ICousreId;  //更新试题的课程ID
            int courseid = int.Parse(Testlib.ICousreId.ToString());

            TbDeanCourse tempCourse = new DeanCourseDAO().GetByID(courseid);
            if (tempCourse != null)
            {
                tempLib.SCourseCode = tempCourse.SCourseCode;  //更新课程的课程代码  修正于10.20日
            }

            tempLib.STitle = Testlib.STitle;  //更新标题
            tempLib.IStuOpen = Testlib.IStuOpen;  //更新是否
            tempLib.SContent = Testlib.SContent; //更新内容
            tempLib.IHardLevel = Testlib.IHardLevel; //更新难易度
            tempLib.IDiffLevel = Testlib.IDiffLevel;//更新区分度
            tempLib.ITeaCatalog = Testlib.ITeaCatalog;
            tempLib.SCharpter = Testlib.SCharpter;//更新所属章节

            tempLib.SAnalysis = Testlib.SAnalysis; //答案分析  添加于12.2日

            if (Testlib.ITeaCatalog != null)//Test
            {
                int ID = int.Parse(Testlib.ITeaCatalog.ToString());
                TeaCatalogDAO Tea = new TeaCatalogDAO();
                TbTeaCatalog temp = Tea.GetByID(ID);
                if (temp != null)
                {
                    tempLib.SCharpter = tempLib.SCharpter + temp.SCaptailName;
                }
            }

            tempLib.SPointers = Testlib.SPointers; //更新知识考点
            tempLib.SAnswer = Testlib.SAnswer;//更新答案
            TLbDao.Update(tempLib);
        }

        //取单项选择题的选项是否全错
        public int OptionsValidate()
        {
            long tempTestLibId = frontCurrentTea.GetCurrentQuestionID();//获取选项的Id
            string whereClause = "I_libID=" + tempTestLibId + "and I_IsTrue=1 ";//获取当前题对应的选项集
            TList<TbTestLibOption> tempOptionList = new TestLibOptionDAO().GetByPage(whereClause, 0, int.MaxValue);
            if (tempOptionList.Count == 1)
            {
                return 1;
            }
            return 0;
        }


        //获取预览试题信息  添加于9.7晚上  test
        public JsonResult GetPreviewData()
        {
            string tempTestLibId = frontCurrentTea.GetCurrentQuestionID().ToString();//获取选项的Id
            int id = int.Parse(tempTestLibId);
            TbTestLib PreviewLib = new TestLibDAO().GetByID(id);

            long tempLibId = frontCurrentTea.GetCurrentQuestionID();//获取选项的Id
            string whereClause = "I_libID=" + tempLibId + "and I_IsTrue=1 ";//获取当前试题正确的选项
            TList<TbTestLibOption> LibOptionList = new TestLibOptionDAO().GetByPage(whereClause, 0, int.MaxValue);
            return Json(new { PreviewLib, LibOptionList }, JsonRequestBehavior.AllowGet);
        }


        /// <summary>
        /// 点击编辑,更新Session为当前选中需编辑的试题的id
        /// </summary>
        /// <param name="id"></param>
        public void ChangeCurrentSessionId(int id, int kind)
        {
            frontCurrentTea.SetCurrentQuestionID(id);//点击编辑将session中的Id更新为当前选中需编辑的试题的id
            frontCurrentTea.SetCurrentQuestionKind(kind);
        }

        //test
        /// <summary>
        /// 根据选择题的ID判断标记被选中的选项是正确选项
        /// </summary>
        /// <param name="ID"> 被选中的option的ID</param>
        public JsonResult ChangeTFOption(int ID)
        {
            //获取当前的判断题的选项
            TbTestLibOption CurrentOption = new TestLibOptionDAO().GetByID(ID);
            if (CurrentOption != null)
            {
                CurrentOption.IIsTrue = 1;
                //更新为正确的选项
                TLOpDao.Update(CurrentOption);
                string whereClause = "I_LibID=" + CurrentOption.ILibId + "and ID !=" + ID;
                //查找另一个选项，把他的istrue更改为0
                TList<TbTestLibOption> AnotherOption = new TestLibOptionDAO().GetByPage(whereClause, 0, int.MaxValue);
                if (AnotherOption.Count > 0)
                {
                    if (AnotherOption[0].IIsTrue != 0)
                    {
                        AnotherOption[0].IIsTrue = 0;
                        TLOpDao.Update(AnotherOption[0]);
                    }

                }



            }
            return Json(CurrentOption, JsonRequestBehavior.AllowGet);

        }



        /// <summary>
        /// 上传试题Excel文件
        /// </summary>
        /// <param name="qqfile">文件名称</param>
        /// <param name="ProblemType">导入试题类型</param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult btnExcelUploadClick(string qqfile, int ProblemType, int CourseID)
        {
            const string FilePath = "/Upload/TestLibFile/";  //文件的保存路径//Server.MapPath(FilePath);//物理存储路径
            string currentUserIDString = null;


            currentUserIDString = frontCurrentTea.GetNo().ToString();//如果当前登陆用户为教师，则获取该教师的id


            string fileName = DateTime.Now.ToString("ddHHmmssff");//名称
            CurrentFileName = fileName;
            string fileType = qqfile.Substring(qqfile.LastIndexOf("."));//类型
            string webFile = FilePath + currentUserIDString + "/UploadFile/" + fileName + fileType;//服务器端路径          

            string uploadPath = "";

            uploadPath = Server.MapPath(FilePath + currentUserIDString + "/UploadFile/");//物理存储路径
            Session["webFile"] = webFile;//服务器端路径文件保存在session中
            //若不存在当前目录则创建
            if (!Directory.Exists(uploadPath))
            {
                Directory.CreateDirectory(uploadPath);
            }
            //流存储
            using (var inputStream = Request.InputStream)
            {
                using (var flieStream = new FileStream(Server.MapPath(webFile), FileMode.Create))
                {
                    inputStream.CopyTo(flieStream);
                }
            }

            FeedBackInformation FBI = new FeedBackInformation();
            FBI = btnImportDataClick(ProblemType, CourseID);
            string ReturnResult = FBI.ReturnResult;
            string Url = FBI.Url;
            System.IO.File.Delete(Server.MapPath(webFile));
            return Json(new { success = true, ReturnResult, Url }, JsonRequestBehavior.AllowGet);
        }



        #region Excel导入试题


        /// <summary>
        /// 根据提交的数据进行导入并返回执行结果
        /// </summary>//
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public FeedBackInformation btnImportDataClick(int ProblemType, int CourseID)
        {


            FeedBackInformation FBI = new FeedBackInformation();//接收 反馈的信息，源数据处理，在存在试题编辑方面的错误的时候返回下载错误试题excel文件的URL
            //共用部分 begin
            string uploadPath = Session["webFile"].ToString();


            //(3)读入源数据的Excel文件;
            string excelPath = Server.MapPath(uploadPath);
            DataTable dt = null;
            if (!System.IO.File.Exists(excelPath))
            {
                return null;
            }
            try
            {
                dt = new RSExcelReader().getTableByExcelpath(excelPath);  //读取数据到表中，第一行为列的说明名,第二行为列名

            }
            catch (Exception e3)
            {


                FBI.ReturnResult = "出错了，读取Excel错误:" + e3.Message.ToString() + ",可能是文件格式出错";
                return FBI;
            }



            //(4)判断此数据是否合格;
            int I_TeaDetailsCount = dt.Rows.Count;
            if (I_TeaDetailsCount < 1)
            {

                FBI.ReturnResult = "出错了，读取Excel格式错误，行数太少!";
                return FBI;
            }
            //(5)读取有效行,并写入临时类
            //只处理第二列获取第一列的数据



            Dictionary<int, List<TbTestLibOption>> RowData = new Dictionary<int, List<TbTestLibOption>>();//将获取到的数据Option放到该容器里面
            int dtCount = dt.Rows.Count;//总行数
            int dtColCount = dt.Columns.Count;//总列数

            /**构建试题的标准模板**/
            DataTable TestLibRecord = new DataTable();//构造记录Testlib的数据集,
            TestLibRecord.Columns.Add("Stile", typeof(System.String));//构建试题stile
            TestLibRecord.Columns.Add("IStuOpen", typeof(System.Int32));//是否对学生公开
            TestLibRecord.Columns.Add("Schapter", typeof(System.String));//所在章
            TestLibRecord.Columns.Add("Section", typeof(System.String));//所在节
            TestLibRecord.Columns.Add("HardLevel", typeof(System.Int32));//难易度系数
            TestLibRecord.Columns.Add("DiffLevel", typeof(System.Int32));//区分度系数
            TestLibRecord.Columns.Add("SPointer", typeof(System.String));//知识点
            TestLibRecord.Columns.Add("SKeyWords", typeof(System.String));//关键字
            TestLibRecord.Columns.Add("SAnalysis", typeof(System.String));//答案解析  添加于12.2日

            //公用部分结束  end
            TestLibExtClass TLEC = new TestLibExtClass();
            TLEC.OptionRecord = RowData;
            TLEC.TestLibRecord = TestLibRecord.Clone();//赋值结构
            TLEC.ErrDataTable = dt.Clone();//复制dt的结构便于返回值
            TLEC.ErrDataTable.Columns.Add("错误原因", typeof(System.String));//错误原因 
            switch (ProblemType)
            {
                case 1://单选题


                    //判断表结构是否合法

                    List<string> SingleTableList = new List<string>();//用于装上传的文件的表头 add by yzp
                    string Singletempheader;
                    for (int i = 0; i < dt.Columns.Count; i++)  //取表头
                    {
                        Singletempheader = dt.Columns[i].ToString();
                        SingleTableList.Add(Singletempheader);
                    }

                    if (ChoiceTableHeaderValidate(SingleTableList)) //调用判断表头是否相匹配的函数
                    {
                        TLEC = MultiOrSingleSelecteHandler(ProblemType, TLEC, dtCount, dtColCount, dt);
                    }
                    else
                    {

                        FBI.ReturnResult = "出错了,导入单选题的模板出错请重新下载模板编辑试题";
                        return FBI;

                    }
                    break;
                case 2://多选题
                    //判断
                    List<string> MultTableList = new List<string>();//用于装上传的文件的表头
                    string MultTempheader;
                    for (int i = 0; i < dt.Columns.Count; i++)  //取表头
                    {
                        MultTempheader = dt.Columns[i].ToString();
                        MultTableList.Add(MultTempheader);
                    }
                    if (ChoiceTableHeaderValidate(MultTableList))//调用判断表头是否相匹配的函数
                    {
                        TLEC = MultiOrSingleSelecteHandler(ProblemType, TLEC, dtCount, dtColCount, dt);
                    }
                    else
                    {
                        FBI.ReturnResult = "出错了,导入多选题的模板格式出错啦！！！请重新下载模板编辑试题";
                        return FBI;

                    }
                    break;

                case 3://判断题
                    List<string> JudgeTableList = new List<string>();//用于装上传的文件的表头
                    string JudgeTempheader;
                    for (int i = 0; i < dt.Columns.Count; i++)  //取表头
                    {
                        JudgeTempheader = dt.Columns[i].ToString();
                        JudgeTableList.Add(JudgeTempheader);
                    }
                    if (JudgeTableHeaderValidate(JudgeTableList))//调用判断表头是否相匹配的函数
                    {
                        TLEC = BinaryChoice(ProblemType, TLEC, dtCount, dtColCount, dt);
                    }
                    else
                    {
                        FBI.ReturnResult = "出错了,导入判断题的模板格式出错啦！！！请重新下载模板编辑试题";
                        return FBI;
                    }
                    break;
                default:
                    break;

            }
            TestLibRecord = TLEC.TestLibRecord;
            int count = TLEC.ErrDataTable.Rows.Count;//用于测试
            RowData = TLEC.OptionRecord;



            int Counttt = TLEC.TestLibRecord.Rows.Count;
            //先处理Testlib集合  //公用部分 begin
            int TLRCount = TestLibRecord.Rows.Count;//总行数
            int TLRColCount = TestLibRecord.Columns.Count;//总列数

            int CurrentProblemType = ProblemType;//获取当前的试题类型
            string SCourseCode = "-1";//当前选中的课程代码

            TbDeanCourse DeanCourseList = new DeanCourseDAO().GetByID(CourseID);
            if (DeanCourseList != null)
            {
                SCourseCode = DeanCourseList.SCourseCode;  //写入试题所属课程的课程号
            }

            //向数据库里面插入数据
            //从第一行开始处理
            for (int i = 0; i < TLRCount; i++)
            {
                long TestLibID;
                int TestNo = i;
                //在这里处理的时候同样需要返回错误的 Datatable
                string Scharter = TestLibRecord.Rows[i][2].ToString();//获取填写的章
                string Section = TestLibRecord.Rows[i][3].ToString();//获取填写的节

                string WhereClause = "S_CaptailName='" + Scharter + "' and I_ParentID=0 and I_DeanCourseID=" + frontCurrentTea.GetCurrentCourseID();//写条件查询大纲表章所在的Id//可能章不存在要考虑进去
                int ScharpterId = -1;//获取章对应的
                TList<TbTeaCatalog> TTC = new TeaCatalogDAO().GetByPage(WhereClause, 0, int.MaxValue);//用于处理章所在id

                int SectionFlag = 0;//默认可以不填写第几张,1表示教师填写了节
                string WhereSectionClause = "";//查询节
                if (Section != null && Section != "")
                {
                    SectionFlag = 1;//标示为教师选择了填写节
                    WhereSectionClause = "S_CaptailName='" + Section + "'";//可能不存在章对应的节
                    //WhereSectionClause = "S_CaptailName='" + Section + "' and I_ParentID!=0 ";//可能不存在章对应的节
                }

                string CurrrentScharpter = Scharter + Section;//组合成Testlib字段里面的Scharpter当前的章和节的组装

                if (TTC.Count > 0)
                {
                    ScharpterId = TTC[0].Id;
                    if (SectionFlag == 1)//说明有节的填写
                    {
                        WhereSectionClause += " and I_ParentID=" + ScharpterId;
                    }
                }
                else
                {
                    DataRow GetErrow = TLEC.ErrDataTable.NewRow();

                    string whereClause = "题目内容='" + TestLibRecord.Rows[i][0].ToString() + "'";
                    DataRow[] CurrrentErrow = dt.Select(whereClause);
                    int coulumsCount = 0;
                    for (coulumsCount = 0; coulumsCount < dt.Columns.Count; coulumsCount++)
                    {

                        GetErrow[coulumsCount] = CurrrentErrow[0][coulumsCount];
                    }
                    GetErrow[coulumsCount] = "错误原因:课程对应的大纲不存在该章,请核对后重新填写";
                    TLEC.ErrDataTable.Rows.Add(GetErrow);
                    continue;//跳出内层循环
                    //报错并提示原因:

                }
                int SectionId = -1;//表示不存在Section
                if (SectionFlag == 1)//教师填写了节进行节的查询
                {
                    TList<TbTeaCatalog> TTCSectionId = new TeaCatalogDAO().GetByPage(WhereSectionClause, 0, int.MaxValue);

                    if (TTCSectionId.Count <= 0)
                    {

                        DataRow GetErrow = TLEC.ErrDataTable.NewRow();

                        string whereClause = "试题内容=" + TestLibRecord.Rows[i][0].ToString();
                        DataRow[] CurrrentErrow = dt.Select();
                        int coulumsCount = 0;
                        for (coulumsCount = 0; coulumsCount < dt.Columns.Count; coulumsCount++)
                        {

                            GetErrow[coulumsCount] = CurrrentErrow[0][coulumsCount];
                        }
                        GetErrow[coulumsCount] = "错误原因:课程对应的大纲不存在对应的节,请核对后重新填写";
                        TLEC.ErrDataTable.Rows.Add(GetErrow);
                        continue;//跳出内层循环
                        //报错并提示原因:
                        //报错
                    }
                    else
                    {
                        SectionId = TTCSectionId[0].Id;

                    }
                }

                TbTestLib TTLInsert = new TbTestLib();
                //获取 每一行数据//在这里同时处理难度系数和区分度系数越界的问题（不在[0,10]之间）


                TTLInsert.ICousreId = CourseID;//绑定课程Id
                TTLInsert.SCourseCode = SCourseCode;//绑定课程的代码;
                TTLInsert.IProblemType = CurrentProblemType;//当前试题类型
                TTLInsert.STitle = TestLibRecord.Rows[i][0].ToString();//获取试题的Stitle
                TTLInsert.IStuOpen = int.Parse(TestLibRecord.Rows[i][1].ToString());//获取是否对学生公开

                TTLInsert.ITeaCatalog = SectionId;//获取节对应的Id
                TTLInsert.IHardLevel = int.Parse(TestLibRecord.Rows[i][4].ToString());//获取试题的难易度系数
                TTLInsert.IDiffLevel = int.Parse(TestLibRecord.Rows[i][5].ToString());//获取试题的区分度系数
                TTLInsert.SKeyWords = TestLibRecord.Rows[i][7].ToString();//获取填写的关键字
                TTLInsert.SPointers = TestLibRecord.Rows[i][6].ToString();//获取填写的知识点
                TTLInsert.SAnalysis = TestLibRecord.Rows[i][8].ToString();//获取填写的答案解析  添加于12.2日
                TTLInsert.SCharpter = CurrrentScharpter;//当前的章节
                TLbDao.Insert(TTLInsert);//向数据库插入该数据Testlib
                TestLibID = TTLInsert.Id;//获取TestLibiD


                List<TbTestLibOption> Opption = RowData[TestNo];
                foreach (var Item in Opption)
                {
                    Item.ILibId = TestLibID;
                    TLOpDao.Insert(Item);//插入Option选项
                }

            }
            int Count = TLEC.ErrDataTable.Rows.Count;
            int TrueCount = dt.Rows.Count - Count;//返回正确的条数
            string StrErrorresult = "没有错误数据";
            if (Count > 0)
            {

                FBI.Url = Printer(TLEC.ErrDataTable);//接收错误试题文件下载的URL
                StrErrorresult = "条,错误数据" + Count + "条,请下载错误试题重新按模板编辑提交";


            }
            FBI.ReturnResult = "成功插入数据" + TrueCount + StrErrorresult;
            return FBI;//test

        }
        #endregion




        #region 多选题和单选题处理
        /// <summary>
        /// 
        /// </summary>
        /// <param name="ProblemType">为单选题或者多选题</param>
        /// <param name="TLEC"></param>
        /// <returns></returns>
        public TestLibExtClass MultiOrSingleSelecteHandler(int ProblemType, TestLibExtClass TLEC, int dtCount, int dtColCount, DataTable dt)
        {

            DataTable TestLibRecord = TLEC.TestLibRecord;
            Dictionary<int, List<TbTestLibOption>> RowData = TLEC.OptionRecord;
            DataTable error = TLEC.ErrDataTable;
            int RecordNo = 0;//标记编号 试题编号初始正确的编号
            for (int i = 0; i < dtCount; i++)
            {
                DataRow dr = TestLibRecord.NewRow();//新建行正确的插入
                int MarkError = 1;//1标示正确，零表示错误,用于存储到error
                int ColumsRecord = 0;//标记当前的TestLib的DataTable为第几列
                Dictionary<string, TbTestLibOption> Option = new Dictionary<string, TbTestLibOption>();//<A,选项内容
                List<TbTestLibOption> TempRecordOption = new List<TbTestLibOption>();
                try
                {
                    for (int j = 0; j < dtColCount; j++)//列数据
                    {
                        string ColumnStr = dt.Columns[j].ColumnName;//获取列的属性
                        string tempStr = ColumnStr.Substring(0, 2);
                        int flag = 1;//1继续在列循环里面执行，0表示退出循环
                        string OptionChoice;//取选项的A,B,C,D,E
                        string DataStr = dt.Rows[i][j].ToString();//获取当前的数据 
                        string TempStr = "选项";
                        int length = ColumnStr.IndexOf("选项");
                        String OptionName="";
                        
                        if (length > -1)//判断为选项
                        {
                            int temp = TempStr.Length;
                            OptionName = ColumnStr.Substring(temp);//获取选项：比如 A，B,C,D,E,...
                            ColumnStr = "选项";
                        }
                        switch (ColumnStr)
                        {

                            case "题目内容(必填)":
                                if (DataStr == null || DataStr == "")//出错处理
                                {

                                    //错误放到error里面
                                    MarkError = 0;
                                    flag = 0;
                                    int Clum = j + 1;//记录错误的列号
                                    string ErrorReason = "第" + Clum + "列,列名：" + dt.Columns[Clum - 1].ColumnName + ",错误原因:题目内容为必填项！！！,请重新填写";
                                    error = CommonPartHandle(dt, error, ErrorReason, i);
                                }
                                else
                                {
                                    dr[ColumsRecord] = DataStr;
                                    ColumsRecord++;
                                }
                                break;
                            case "正确答案(必填)":
                                try
                                {
                                    if (ProblemType == 1)
                                    {
                                        if (DataStr.Length == 1 && Option.ContainsKey(DataStr))
                                        {

                                            Option[DataStr].IIsTrue = 1;
                                        }
                                        else
                                        {
                                            MarkError = 0;
                                            flag = 0;
                                            int Clum = j + 1;//记录错误的列号
                                            string ErrorReason = "第" + Clum + "列,列名：" + dt.Columns[Clum - 1].ColumnName + ",错误原因:单选类型填写答案不符合规范,只能由[A-F]之间的大写的英文字母且必须是选项出现了的";
                                            error = CommonPartHandle(dt, error, ErrorReason, i);
                                            break;//跳出内层循环
                                        }
                                    }
                                    else
                                    {
                                        string[] TrueChoice = DataStr.Split(new char[] { ';' });
                                        int IsTrue = 1;//标示正确与否,1正确，0错误
                                        foreach (var Item in TrueChoice)
                                        {
                                            if (Item.Length == 1 && Option.ContainsKey(Item))
                                            {
                                                Option[Item].IIsTrue = 1;//标示为正确
                                            }
                                            else
                                            {
                                                //报错处理
                                                IsTrue = 0;//标示出错了
                                                MarkError = 0;
                                                flag = 0;
                                                int Clum = j + 1;//记录错误的列号
                                                string ErrorReason = "第" + Clum + "列,列名：" + dt.Columns[Clum - 1].ColumnName + ",错误原因:正确答案标标识填写出错";
                                                error = CommonPartHandle(dt, error, ErrorReason, i);
                                                break;
                                            }
                                        }
                                        if (IsTrue == 0)
                                        { break; }
                                    }
                                    //取出修改后的Option
                                    foreach (var Item in Option)
                                    {
                                        TempRecordOption.Add(Item.Value);
                                    }

                                }
                                catch (Exception Ec)
                                {
                                    MarkError = 0;
                                    int Clum = j + 1;//记录错误的列号
                                    string ErrorReason = "第" + Clum + "列,列名：" + dt.Columns[Clum - 1].ColumnName + ",错误原因:" + Ec.Message.ToString();
                                    error = CommonPartHandle(dt, error, ErrorReason, i);
                                }
                                break;
                            case "是否对学生公开(填是或否)(必填)":
                                if (DataStr.Equals("是"))
                                {
                                    dr[ColumsRecord] = 1;
                                    ColumsRecord++;
                                }
                                else if (DataStr.Equals("否"))
                                {
                                    dr[ColumsRecord] = 0;
                                    ColumsRecord++;
                                }
                                else//出错处理
                                {
                                    MarkError = 0;
                                    flag = 0;
                                    int Clum = j + 1;//记录错误的列号
                                    string ErrorReason = "第" + Clum + "列,列名：" + dt.Columns[Clum - 1].ColumnName + ",错误原因:是否对学生公开无效";
                                    error = CommonPartHandle(dt, error, ErrorReason, i);
                                }
                                break;
                            case "难易度(0,10)":
                            case "区分度(0,10)":
                                try
                                {
                                    int Idegree = int.Parse(DataStr);
                                    if (Idegree < 0 || Idegree > 10 && (DataStr != null && DataStr != ""))
                                    {
                                        MarkError = 0;
                                        flag = 0;
                                        int Clum = j + 1;//记录错误的列号
                                        string ErrorReason = "第" + Clum + "列,列名：" + dt.Columns[Clum - 1].ColumnName + ",错误原因:系数的取值范围在[0,10]之间且为整数";
                                        error = CommonPartHandle(dt, error, ErrorReason, i);
                                        break;//跳出内层循环
                                    }
                                    dr[ColumsRecord] = int.Parse(DataStr);//这些列为INT类型
                                    ColumsRecord++;
                                }
                                catch (Exception e)
                                {

                                    MarkError = 0;
                                    flag = 0;
                                    int Clum = j + 1;//记录错误的列号
                                    string ErrorReason = "第" + Clum + "列,列名：" + dt.Columns[Clum - 1].ColumnName + ",错误原因:系数的取值范围在[0,10]之间且为整数,不能为其它非指定的字符";
                                    error = CommonPartHandle(dt, error, ErrorReason, i);

                                }
                                break;
                            case "所在大纲章(必填)":
                            case "所在大纲节":
                            case "知识点":
                            case "关键字":
                            case "答案解析":  //添加于12.2日
                                dr[ColumsRecord] = DataStr;
                                ColumsRecord++;
                                break;
                            case "选项":
                                if (DataStr != null && DataStr != "")
                                {
                                    OptionChoice = OptionName;
                                    TbTestLibOption TTLO = new TbTestLibOption();
                                    TTLO.SOptionName = DataStr;
                                    TTLO.IIsTrue = 0;//默认为错误
                                    Option.Add(OptionChoice, TTLO);
                                }
                                
                                break;

                            default:

                                break;

                        }
                        if (flag == 0)
                        { break; }
                    }
                    if (MarkError != 0)//当不报错的时候添加
                    {
                        TestLibRecord.Rows.Add(dr);
                        RowData.Add(RecordNo, TempRecordOption);
                        RecordNo++;
                    }

                }
                catch (Exception Error)
                {
                    MarkError = 0;
                    string ErrorReason = "错误原因:" + Error.Message.ToString();
                    error = CommonPartHandle(dt, error, ErrorReason, i);
                    break;//跳出内层循环
                }


            }
            TLEC.ErrDataTable = error;
            int Countt = TLEC.ErrDataTable.Rows.Count;
            TLEC.TestLibRecord = TestLibRecord;
            int Count = TestLibRecord.Rows.Count;
            TLEC.OptionRecord = RowData;

            return TLEC;
        }
        #endregion





        #region 判断题处理函数

        //binary
        /// <summary>
        /// 处理判断题
        /// </summary>
        /// <param name="ProblemType"></param>
        /// <param name="TLEC"></param>
        /// <param name="dtCount"></param>
        /// <param name="dtColCount"></param>
        /// <param name="dt"></param>
        /// <returns></returns>
        public TestLibExtClass BinaryChoice(int ProblemType, TestLibExtClass TLEC, int dtCount, int dtColCount, DataTable dt)
        {

            DataTable TestLibRecord = TLEC.TestLibRecord;
            Dictionary<int, List<TbTestLibOption>> RowData = TLEC.OptionRecord;
            DataTable error = TLEC.ErrDataTable;//获取数据和结构/如果使用clone仅为复制结构
            int RecordNo = 0;//标记编号 试题编号初始正确的编号
            for (int i = 0; i < dtCount; i++)
            {
                DataRow dr = TestLibRecord.NewRow();//新建行正确的插入
                int MarkError = 1;// 1标示正确，零表示错误,用于存储到error
                int ColumsRecord = 0;//标记当前的TestLib的DataTable为第几列
                Dictionary<string, TbTestLibOption> Option = new Dictionary<string, TbTestLibOption>();//<A,选项内容
                List<TbTestLibOption> TempRecordOption = new List<TbTestLibOption>();//临时记录
                try
                {
                    for (int j = 0; j < dtColCount; j++)//列数据
                    {
                        int flag = 1;//1表示正确不退出当前的列循环,0表示退出当前列循环
                        string ColumnStr = dt.Columns[j].ColumnName;//获取列的属性
                        string DataStr = dt.Rows[i][j].ToString();//获取当前的数据
                        switch (ColumnStr)//根据列属性
                        {

                            case "题目内容(必填)":
                                if (DataStr == null || DataStr == "")//出错处理
                                {

                                    //错误放到error里面
                                    MarkError = 0;
                                    flag = 0;
                                    int Clum = j + 1;//记录错误的列号
                                    string ErrorReason = "第" + Clum + "列,列名：" + dt.Columns[Clum - 1].ColumnName + ",错误原因:题目内容为必填项！！！,请重新填写";
                                    error = CommonPartHandle(dt, error, ErrorReason, i);
                                }
                                else
                                {
                                    dr[ColumsRecord] = DataStr;
                                    ColumsRecord++;
                                }
                                break;
                            case "正确答案(正确或错误)(必填)":
                                try
                                {
                                    TbTestLibOption TTLO1 = new TbTestLibOption();//选项1标示正确
                                    TTLO1.SOptionName = "正确";
                                    TTLO1.IIsTrue = 1;//默认的情况下都为正确
                                    TbTestLibOption TTLO2 = new TbTestLibOption();//选项1标示错误
                                    TTLO2.SOptionName = "错误";
                                    TTLO2.IIsTrue = 1;//默认的情况下都为正确
                                    Option.Add("A", TTLO1);
                                    Option.Add("B", TTLO2);
                                    if (DataStr.Equals("√"))
                                    {
                                        Option["A"].IIsTrue = 1;
                                        Option["B"].IIsTrue = 0;
                                    }
                                    else if (DataStr.Equals("×"))
                                    {
                                        Option["A"].IIsTrue = 0;
                                        Option["B"].IIsTrue = 1;
                                    }
                                    else
                                    {
                                        //错误放到error里面
                                        MarkError = 0;
                                        flag = 0;
                                        int Clum = j + 1;//记录错误的列号
                                        string ErrorReason = "第" + Clum + "列,列名：" + dt.Columns[Clum - 1].ColumnName + ",错误原因:正确答案标示不在指定的(正确,错误)";
                                        error = CommonPartHandle(dt, error, ErrorReason, i);
                                        break;//跳出内层循环   

                                    }
                                    //将产生的正确和错误的选项放到TempRecordOption里面
                                    foreach (var Item in Option)
                                    {
                                        TempRecordOption.Add(Item.Value);
                                    }

                                }
                                catch (Exception Ec)
                                {
                                    MarkError = 0;
                                    flag = 0;
                                    int Clum = j + 1;//记录错误的列号
                                    string ErrorReason = "第" + Clum + "列,列名：" + dt.Columns[Clum - 1].ColumnName + ",错误原因:" + Ec.Message.ToString();
                                    error = CommonPartHandle(dt, error, ErrorReason, i);
                                }
                                break;
                            case "是否对学生公开(填是或否)(必填)":
                                if (DataStr.Equals("是"))
                                {
                                    dr[ColumsRecord] = 1;
                                    ColumsRecord++;
                                }
                                else if (DataStr.Equals("否"))
                                {
                                    dr[ColumsRecord] = 0;
                                    ColumsRecord++;
                                }
                                else//出错处理
                                {
                                    MarkError = 0;
                                    flag = 0;
                                    int Clum = j + 1;//记录错误的列号
                                    string ErrorReason = "第" + Clum + "列,列名：" + dt.Columns[Clum - 1].ColumnName + ",错误原因:是否对学生公开无效";
                                    error = CommonPartHandle(dt, error, ErrorReason, i);
                                }
                                break;
                            case "难易度(0,10)":
                            case "区分度(0,10)":
                                try
                                {
                                    int Idegree = int.Parse(DataStr);
                                    if ((Idegree < 0 || Idegree > 10) && (DataStr != null && DataStr != ""))
                                    {
                                        MarkError = 0;
                                        flag = 0;
                                        int Clum = j + 1;//记录错误的列号
                                        string ErrorReason = "第" + Clum + "列,列名：" + dt.Columns[Clum - 1].ColumnName + ",错误原因:系数的取值范围在[0,10]之间且为整数";
                                        error = CommonPartHandle(dt, error, ErrorReason, i);
                                        break;//跳出内层循环
                                    }
                                    dr[ColumsRecord] = int.Parse(DataStr);//这些列为INT类型
                                    ColumsRecord++;
                                }
                                catch (Exception e)
                                {

                                    MarkError = 0;
                                    flag = 0;
                                    int Clum = j + 1;//记录错误的列号
                                    string ErrorReason = "第" + Clum + "列,列名：" + dt.Columns[Clum - 1].ColumnName + ",错误原因:系数的取值范围在[0,10]之间且为整数,不能是其他非指定的类型";
                                    error = CommonPartHandle(dt, error, ErrorReason, i);

                                }
                                break;
                            case "所在大纲章(必填)":
                            case "所在大纲节":
                            case "知识点":
                            case "关键字":
                            case "答案解析":   //添加于12.2日
                                dr[ColumsRecord] = DataStr;
                                ColumsRecord++;
                                break;
                            default:
                                break;

                        }
                        if (flag == 0)//跳出当前列循环
                        {
                            break;
                        }
                    }
                    if (MarkError != 0)//当不报错的时候添加
                    {
                        TestLibRecord.Rows.Add(dr);
                        RowData.Add(RecordNo, TempRecordOption);
                        RecordNo++;
                    }
                }
                catch (Exception Error)
                {
                    string ErrorReason = "错误原因:" + Error.ToString();
                    error = CommonPartHandle(dt, error, ErrorReason, i);
                }
            }

            TLEC.ErrDataTable = error;
            TLEC.TestLibRecord = TestLibRecord;
            TLEC.OptionRecord = RowData;
            return TLEC;

        }


        #endregion



        /// <summary>
        /// 返回添加了新的错误的Datatable Error
        /// </summary>
        /// <param name="dt">源数据</param>
        /// <param name="error">错误行收集 DataTable error</param>
        /// <param name="ErrorReason">错误缘由</param>
        /// <param name="Row">当前错误在源数据所在的行序号</param>
        /// <returns></returns>
        public DataTable CommonPartHandle(DataTable dt, DataTable error, string ErrorReason, int Row)
        {

            DataRow GetErrow = error.NewRow();
            int coulumsCount = 0;
            for (coulumsCount = 0; coulumsCount < dt.Columns.Count; coulumsCount++)
            {

                GetErrow[coulumsCount] = dt.Rows[Row][coulumsCount];
            }
            GetErrow[coulumsCount] = ErrorReason;
            error.Rows.Add(GetErrow);
            return error;
        }



        #region 判断题模板验证
        /// <summary>
        /// 判断上传的excel表格的表头是否与模板的表头匹配（判断题）  添加于10.21日 add by yzp
        /// </summary>
        /// <param name="tableHead"></param>
        /// <returns></returns>
        public bool JudgeTableHeaderValidate(List<string> tableHead)
        {
            string[] header = new string[] { "题目内容(必填)", "正确答案(正确或错误)(必填)", "是否对学生公开(填是或否)(必填)", "所在大纲章(必填)", "所在大纲节", "难易度(0,10)", "区分度(0,10)", "知识点", "关键字", "答案解析" };//定义选择题的表头固定格式，用于验证
            if (tableHead.Count != header.Length) //列数不同
            {
                return false;
            }
            else
            {

                for (int i = 0; i < header.Length; i++)
                {
                    string table = tableHead[i];
                    string headerstr = header[i];
                    if (tableHead[i] != header[i])
                    {

                        return false; //对应列不匹配
                    }
                }
            }
            return true;
        }

        #endregion




        #region 选择题模板验证
        /// <summary>
        /// 判断上传的excel表格的表头是否与模板的表头匹配（选择题）  添加于10.21日  add by yzp
        /// </summary>  
        /// <param name="tableHead"></param>
        /// <returns></returns>
        public bool ChoiceTableHeaderValidate(List<string> tableHead)
        {
            string[] header = new string[] { "题目内容(必填)", "选项A", "选项B", "选项C", "选项D", "选项E", "选项F", "选项G", "选项H", "选项I", "选项G", "选项K","选项K","选项M","选项N" ,"正确答案(必填)", "是否对学生公开(填是或否)(必填)", "所在大纲章(必填)", "所在大纲节", "难易度(0,10)", "区分度(0,10)", "知识点", "关键字", "答案解析" };//定义选择题的表头固定格式，用于验证
            List<string> HeaderList = new List<string>(); //存放表头
            foreach (var item in header)
            {
                HeaderList.Add(item);
            }

            if (tableHead.Count < 10)//当导入的试题的表头数目少于10视为无效的excel
            {
                return false;
            }
            else
            {
                for (int i = 0; i < tableHead.Count; i++)
                {
                    string tempHeader = tableHead[i];//当前的表头
                    
                    if (!HeaderList.Contains(tempHeader))//当表头不在预设的里面返回错误
                    {
                        return false;
                    }
                }
                //同时对固有的表格栏进行锁定
               
            }
            return true;
        }

        #endregion



        #region 导出Excel操作
        ///
        /// <summary>
        /// 将DataTable error生成 Excel供下载并返回下载路径
        /// </summary>
        /// <param name="Error"></param>
        /// <returns></returns>
        public string Printer(DataTable Error)
        {

            const string FilePath = "/Upload/TestLibFile/ErrorUpload/";  //文件的保存路径//Server.MapPath(FilePath);//物理存储路径
            string ErrorFile = "导出试题错误" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".xls";
            if (!Directory.Exists(Server.MapPath(FilePath)))
            {
                Directory.CreateDirectory(Server.MapPath(FilePath));
            }

            string Path = Server.MapPath(FilePath) + ErrorFile;
            ExcelHelper.CreateExcel(Error, Path, ErrorFile);
            return FilePath + ErrorFile;
        }

        #endregion
    }
}
